<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>React规范 | 孙加俊的个人博客</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/sjj-blog/favicon.ico">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/sjj-blog/assets/css/0.styles.a5cb6817.css" as="style"><link rel="preload" href="/sjj-blog/assets/js/app.ab5bad9b.js" as="script"><link rel="preload" href="/sjj-blog/assets/js/3.136f62ef.js" as="script"><link rel="preload" href="/sjj-blog/assets/js/1.a27fba8e.js" as="script"><link rel="preload" href="/sjj-blog/assets/js/19.7e0f4bf8.js" as="script"><link rel="prefetch" href="/sjj-blog/assets/js/10.9271e5b8.js"><link rel="prefetch" href="/sjj-blog/assets/js/11.67b9ea44.js"><link rel="prefetch" href="/sjj-blog/assets/js/12.f69e6353.js"><link rel="prefetch" href="/sjj-blog/assets/js/13.ace41b19.js"><link rel="prefetch" href="/sjj-blog/assets/js/14.78670b1e.js"><link rel="prefetch" href="/sjj-blog/assets/js/15.b0aaec82.js"><link rel="prefetch" href="/sjj-blog/assets/js/16.f0d479dc.js"><link rel="prefetch" href="/sjj-blog/assets/js/17.1bacbab3.js"><link rel="prefetch" href="/sjj-blog/assets/js/18.2237a65f.js"><link rel="prefetch" href="/sjj-blog/assets/js/20.5c098df8.js"><link rel="prefetch" href="/sjj-blog/assets/js/21.45bd5038.js"><link rel="prefetch" href="/sjj-blog/assets/js/4.cc582e42.js"><link rel="prefetch" href="/sjj-blog/assets/js/5.9c9443fe.js"><link rel="prefetch" href="/sjj-blog/assets/js/6.370fb6dd.js"><link rel="prefetch" href="/sjj-blog/assets/js/7.e5d26899.js"><link rel="prefetch" href="/sjj-blog/assets/js/8.f6b78670.js"><link rel="prefetch" href="/sjj-blog/assets/js/9.d915a2b8.js">
    <link rel="stylesheet" href="/sjj-blog/assets/css/0.styles.a5cb6817.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-1aefc0b4><div data-v-1aefc0b4><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-1aefc0b4 data-v-1aefc0b4><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>孙加俊的个人博客</h3> <p class="description" data-v-25ba6db2 data-v-25ba6db2></p> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>孙加俊</span>
            
          <span data-v-25ba6db2>2017 - </span>
          2023
        </a></span></div></div> <div class="hide" data-v-1aefc0b4><header class="navbar" data-v-1aefc0b4><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/sjj-blog/" class="home-link router-link-active"><img src="/sjj-blog/logo.png" alt="孙加俊的个人博客" class="logo"> <span class="site-name">孙加俊的个人博客</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/sjj-blog/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      技术栈
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/sjj-blog/categories/规范/" class="nav-link"><i class="undefined"></i>
  规范
</a></li><li class="dropdown-item"><!----> <a href="/sjj-blog/categories/原生JS/" class="nav-link"><i class="undefined"></i>
  原生JS
</a></li></ul></div></div><div class="nav-item"><a href="/sjj-blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/sjj-blog/docs/theme-reco/" class="nav-link"><i class="undefined"></i>
  vuepress-reco
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系我
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/sir-jun" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-1aefc0b4></div> <aside class="sidebar" data-v-1aefc0b4><div class="personal-info-wrapper" data-v-39576ba9 data-v-1aefc0b4><img src="/sjj-blog/avatar.png" alt="author-avatar" class="personal-img" data-v-39576ba9> <h3 class="name" data-v-39576ba9>
    孙加俊
  </h3> <div class="num" data-v-39576ba9><div data-v-39576ba9><h3 data-v-39576ba9>11</h3> <h6 data-v-39576ba9>Articles</h6></div> <div data-v-39576ba9><h3 data-v-39576ba9>3</h3> <h6 data-v-39576ba9>Tags</h6></div></div> <ul class="social-links" data-v-39576ba9></ul> <hr data-v-39576ba9></div> <nav class="nav-links"><div class="nav-item"><a href="/sjj-blog/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      技术栈
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/sjj-blog/categories/规范/" class="nav-link"><i class="undefined"></i>
  规范
</a></li><li class="dropdown-item"><!----> <a href="/sjj-blog/categories/原生JS/" class="nav-link"><i class="undefined"></i>
  原生JS
</a></li></ul></div></div><div class="nav-item"><a href="/sjj-blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/sjj-blog/docs/theme-reco/" class="nav-link"><i class="undefined"></i>
  vuepress-reco
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系我
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/sir-jun" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>React规范</h3> <!----> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>孙加俊</span>
            
          <span data-v-25ba6db2>2017 - </span>
          2023
        </a></span></div></div> <div data-v-1aefc0b4><main class="page"><section><div class="page-title"><h1 class="title">React规范</h1> <div data-v-f875f3fc><i class="iconfont reco-account" data-v-f875f3fc><span data-v-f875f3fc>孙加俊</span></i> <i class="iconfont reco-date" data-v-f875f3fc><span data-v-f875f3fc>7/20/2023</span></i> <!----> <i class="tags iconfont reco-tag" data-v-f875f3fc><span class="tag-item" data-v-f875f3fc>规范</span></i></div></div> <div class="theme-reco-content content__default"><h1 id="react-规范"><a href="#react-规范" class="header-anchor">#</a> React 规范</h1> <h2 id="基本规则"><a href="#基本规则" class="header-anchor">#</a> 基本规则</h2> <ul><li>每个文件只包含一个 React 类组件
<ul><li>但是多个函数式组件可以放到一个文件中，eslint: react/no-multi-comp</li></ul></li> <li>一般使用 JSX 语法</li> <li>除非是在非 JSX 文件中初始化应用，否则不要使用 React.createElement</li></ul> <h2 id="命名规范"><a href="#命名规范" class="header-anchor">#</a> 命名规范</h2> <ul><li>组件文件扩展名</li></ul> <p>使用 TypeScript，文件扩展名为 .tsx</p> <ul><li>组件文件名</li></ul> <p>如果是组件文件，则使用 大驼峰，如 MyComponent.tsx</p> <p>如果组件是一个目录，则组件主入口命名为 index，如 index.tsx</p> <ul><li>引用命名</li></ul> <p>React 组件使用 大驼峰，组件实例使用 小驼峰，eslint: react/jsx-pascal-case</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// bad</span>
<span class="token keyword">import</span> reservationCard <span class="token keyword">from</span> <span class="token string">'./ReservationCard'</span>

<span class="token comment">// good</span>
<span class="token keyword">import</span> ReservationCard <span class="token keyword">from</span> <span class="token string">'./ReservationCard'</span>

<span class="token comment">// bad</span>
<span class="token keyword">const</span> ReservationItem <span class="token operator">=</span> <span class="token operator">&lt;</span>ReservationCard <span class="token operator">/</span><span class="token operator">&gt;</span>

<span class="token comment">// good</span>
<span class="token keyword">const</span> reservationItem <span class="token operator">=</span> <span class="token operator">&lt;</span>ReservationCard <span class="token operator">/</span><span class="token operator">&gt;</span>
</code></pre></div><ul><li>组件命名</li></ul> <p>使用文件名作为组件名字，例如, ReservationCard.js 应该包含名为 ReservationCard 的引用，然而对于文件夹中的根组件, 使用 index.js 作为文件名，使用文件夹的名字作为组件的名字</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// bad</span>
<span class="token keyword">import</span> Footer <span class="token keyword">from</span> <span class="token string">'./Footer/Footer'</span>

<span class="token comment">// bad</span>
<span class="token keyword">import</span> Footer <span class="token keyword">from</span> <span class="token string">'./Footer/index'</span>

<span class="token comment">// good</span>
<span class="token keyword">import</span> Footer <span class="token keyword">from</span> <span class="token string">'./Footer'</span>
</code></pre></div><ul><li>组件属性名</li></ul> <p>React DOM 使用小驼峰式命名法来定义属性的名称，而不使用 HTML 属性名称的命名约定，例如</p> <div class="language-html extra-class"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token special-attr"><span class="token attr-name">onClick</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token value javascript language-javascript"><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>handler<span class="token punctuation">}</span></span></span></span> <span class="token punctuation">/&gt;</span></span>
</code></pre></div><h2 id="class-component-vs-functional-component"><a href="#class-component-vs-functional-component" class="header-anchor">#</a> Class Component VS Functional Component</h2> <p>只允许使用 Class Component 和 Functional Component 两种形态来书写组件，建议尽量使用函数式组件配合 Hooks 来进行开发</p> <h2 id="对齐"><a href="#对齐" class="header-anchor">#</a> 对齐</h2> <p>遵循以下JSX语法的对齐风格，eslint: react/jsx-closing-bracket-location</p> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">superLongParam</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>bar<span class="token punctuation">'</span></span>
     <span class="token attr-name">anotherSuperLongParam</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>baz<span class="token punctuation">'</span></span> <span class="token punctuation">/&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
  <span class="token attr-name">superLongParam</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>bar<span class="token punctuation">'</span></span>
  <span class="token attr-name">anotherSuperLongParam</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>baz<span class="token punctuation">'</span></span>
<span class="token punctuation">/&gt;</span></span>

<span class="token comment">// 如果props适合一行，那么保持在同一行。</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>bar<span class="token punctuation">'</span></span> <span class="token punctuation">/&gt;</span></span>

<span class="token comment">// children 正常缩进</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
  <span class="token attr-name">superLongParam</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>bar<span class="token punctuation">'</span></span>
  <span class="token attr-name">anotherSuperLongParam</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>baz<span class="token punctuation">'</span></span>
<span class="token punctuation">&gt;</span></span><span class="token plain-text">
  </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Quux</span></span> <span class="token punctuation">/&gt;</span></span><span class="token plain-text">
</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token class-name">Foo</span></span><span class="token punctuation">&gt;</span></span>

<span class="token comment">// bad</span>
<span class="token punctuation">{</span>showButton <span class="token operator">&amp;&amp;</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Button</span></span> <span class="token punctuation">/&gt;</span></span>
<span class="token punctuation">}</span>

<span class="token comment">// bad</span>
<span class="token punctuation">{</span>
  showButton <span class="token operator">&amp;&amp;</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Button</span></span> <span class="token punctuation">/&gt;</span></span>
<span class="token punctuation">}</span>

<span class="token comment">// good</span>
<span class="token punctuation">{</span>showButton <span class="token operator">&amp;&amp;</span> <span class="token punctuation">(</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Button</span></span> <span class="token punctuation">/&gt;</span></span>
<span class="token punctuation">)</span><span class="token punctuation">}</span>

<span class="token comment">// good</span>
<span class="token punctuation">{</span>showButton <span class="token operator">&amp;&amp;</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Button</span></span> <span class="token punctuation">/&gt;</span></span><span class="token punctuation">}</span>
</code></pre></div><h2 id="空格"><a href="#空格" class="header-anchor">#</a> 空格</h2> <ul><li>自闭合的标签前要加一个空格，eslint: no-multi-spaces, react/jsx-tag-spacing</li></ul> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span><span class="token punctuation">/&gt;</span></span>

<span class="token comment">// very bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>                 <span class="token punctuation">/&gt;</span></span>

<span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
 <span class="token punctuation">/&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token punctuation">/&gt;</span></span>
</code></pre></div><ul><li>不要在 JSX 的花括号里边加空格，eslint: react/jsx-curly-spacing</li></ul> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">bar</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span> baz <span class="token punctuation">}</span></span> <span class="token punctuation">/&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">bar</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>baz<span class="token punctuation">}</span></span> <span class="token punctuation">/&gt;</span></span>
</code></pre></div><h2 id="引号"><a href="#引号" class="header-anchor">#</a> 引号</h2> <p>JSX 属性要使用单引号，与其他普通 JS 保持一致</p> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>bar<span class="token punctuation">&quot;</span></span> <span class="token punctuation">/&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>bar<span class="token punctuation">'</span></span> <span class="token punctuation">/&gt;</span></span>

<span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> <span class="token literal-property property">left</span><span class="token operator">:</span> <span class="token string">&quot;20px&quot;</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span> <span class="token punctuation">/&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> <span class="token literal-property property">left</span><span class="token operator">:</span> <span class="token string">'20px'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span> <span class="token punctuation">/&gt;</span></span>
</code></pre></div><h2 id="属性"><a href="#属性" class="header-anchor">#</a> 属性</h2> <ul><li>属性名使用 小驼峰</li></ul> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
  <span class="token attr-name">UserName</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>hello<span class="token punctuation">'</span></span>
  <span class="token attr-name">phone_number</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">12345678</span><span class="token punctuation">}</span></span>
<span class="token punctuation">/&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
  <span class="token attr-name">userName</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>hello<span class="token punctuation">'</span></span>
  <span class="token attr-name">phoneNumber</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">12345678</span><span class="token punctuation">}</span></span>
<span class="token punctuation">/&gt;</span></span>
</code></pre></div><ul><li>当属性值为true时可以省略， eslint: react/jsx-boolean-value</li></ul> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
  <span class="token attr-name">hidden</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token boolean">true</span><span class="token punctuation">}</span></span>
<span class="token punctuation">/&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
  <span class="token attr-name">hidden</span>
<span class="token punctuation">/&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">hidden</span> <span class="token punctuation">/&gt;</span></span>
</code></pre></div><ul><li>避免使用数组的索引作为 key 属性值, 建议使用稳定的ID，eslint: react/no-array-index-key</li></ul> <blockquote><p>原因：不使用稳定的 ID 会对性能产生副作用并且组件状态会出问题，是一种反模式</p></blockquote> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token punctuation">{</span>todos<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">todo<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Todo</span></span>
    <span class="token spread"><span class="token punctuation">{</span><span class="token operator">...</span>todo<span class="token punctuation">}</span></span>
    <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>index<span class="token punctuation">}</span></span>
  <span class="token punctuation">/&gt;</span></span>
<span class="token punctuation">)</span><span class="token punctuation">}</span>

<span class="token comment">// good</span>
<span class="token punctuation">{</span>todos<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token parameter">todo</span> <span class="token operator">=&gt;</span> <span class="token punctuation">(</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Todo</span></span>
    <span class="token spread"><span class="token punctuation">{</span><span class="token operator">...</span>todo<span class="token punctuation">}</span></span>
    <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>todo<span class="token punctuation">.</span>id<span class="token punctuation">}</span></span>
  <span class="token punctuation">/&gt;</span></span>
<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span>
</code></pre></div><ul><li>为所有的非必需属性定义使用 defaultProps 明确的默认值</li></ul> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token keyword">function</span> <span class="token constant">SFC</span> <span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> foo<span class="token punctuation">,</span> bar<span class="token punctuation">,</span> children <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">{</span>foo<span class="token punctuation">}</span><span class="token punctuation">{</span>bar<span class="token punctuation">}</span><span class="token punctuation">{</span>children<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token punctuation">}</span>
<span class="token constant">SFC</span><span class="token punctuation">.</span>propTypes <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token literal-property property">foo</span><span class="token operator">:</span> PropTypes<span class="token punctuation">.</span>number<span class="token punctuation">.</span>isRequired<span class="token punctuation">,</span>
  <span class="token literal-property property">bar</span><span class="token operator">:</span> PropTypes<span class="token punctuation">.</span>string<span class="token punctuation">,</span>
  <span class="token literal-property property">children</span><span class="token operator">:</span> PropTypes<span class="token punctuation">.</span>node
<span class="token punctuation">}</span>

<span class="token comment">// good</span>
<span class="token keyword">function</span> <span class="token constant">SFC</span> <span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> foo<span class="token punctuation">,</span> bar<span class="token punctuation">,</span> children <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">{</span>foo<span class="token punctuation">}</span><span class="token punctuation">{</span>bar<span class="token punctuation">}</span><span class="token punctuation">{</span>children<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token punctuation">}</span>
<span class="token constant">SFC</span><span class="token punctuation">.</span>propTypes <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token literal-property property">foo</span><span class="token operator">:</span> PropTypes<span class="token punctuation">.</span>number<span class="token punctuation">.</span>isRequired<span class="token punctuation">,</span>
  <span class="token literal-property property">bar</span><span class="token operator">:</span> PropTypes<span class="token punctuation">.</span>string<span class="token punctuation">,</span>
  <span class="token literal-property property">children</span><span class="token operator">:</span> PropTypes<span class="token punctuation">.</span>node
<span class="token punctuation">}</span>
<span class="token constant">SFC</span><span class="token punctuation">.</span>defaultProps <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token literal-property property">bar</span><span class="token operator">:</span> <span class="token string">''</span><span class="token punctuation">,</span>
  <span class="token literal-property property">children</span><span class="token operator">:</span> <span class="token keyword">null</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="refs"><a href="#refs" class="header-anchor">#</a> Refs</h2> <p>避免使用字符串引用，请使用回调函数作为引用，eslint: react/no-string-refs</p> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
  <span class="token attr-name">ref</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>myRef<span class="token punctuation">'</span></span>
<span class="token punctuation">/&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
  <span class="token attr-name">ref</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token parameter">ref</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span>myRef <span class="token operator">=</span> ref <span class="token punctuation">}</span><span class="token punctuation">}</span></span>
<span class="token punctuation">/&gt;</span></span>
</code></pre></div><h2 id="圆括号"><a href="#圆括号" class="header-anchor">#</a> 圆括号</h2> <p>当 JSX 标签超过一行时使用圆括号包裹， eslint: react/wrap-multilines</p> <div class="language-jsx extra-class"><pre class="language-jsx"><code>
<span class="token comment">// bad</span>
<span class="token function">render</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">MyComponent</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>long body<span class="token punctuation">'</span></span> <span class="token attr-name">foo</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>bar<span class="token punctuation">'</span></span><span class="token punctuation">&gt;</span></span><span class="token plain-text">
           </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">MyChild</span></span> <span class="token punctuation">/&gt;</span></span><span class="token plain-text">
         </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token class-name">MyComponent</span></span><span class="token punctuation">&gt;</span></span>
<span class="token punctuation">}</span>

<span class="token comment">// good</span>
<span class="token function">render</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">MyComponent</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>long body<span class="token punctuation">'</span></span> <span class="token attr-name">foo</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>bar<span class="token punctuation">'</span></span><span class="token punctuation">&gt;</span></span><span class="token plain-text">
      </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">MyChild</span></span> <span class="token punctuation">/&gt;</span></span><span class="token plain-text">
    </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token class-name">MyComponent</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// good, when single line</span>
<span class="token function">render</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> body <span class="token operator">=</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span><span class="token plain-text">hello</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
  <span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">MyComponent</span></span><span class="token punctuation">&gt;</span></span><span class="token punctuation">{</span>body<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token class-name">MyComponent</span></span><span class="token punctuation">&gt;</span></span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="标签"><a href="#标签" class="header-anchor">#</a> 标签</h2> <ul><li>没有子元素的标签请自闭合，eslint: react/self-closing-comp</li></ul> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>stuff<span class="token punctuation">'</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span><span class="token class-name">Foo</span></span><span class="token punctuation">&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>stuff<span class="token punctuation">'</span></span> <span class="token punctuation">/&gt;</span></span>
</code></pre></div><ul><li>如果组件包含多行属性，在新的一行闭合标签，eslint: react/jsx-closing-bracket-location</li></ul> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
  <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>bar<span class="token punctuation">'</span></span>
  <span class="token attr-name">baz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>baz<span class="token punctuation">'</span></span> <span class="token punctuation">/&gt;</span></span>

<span class="token comment">// good</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Foo</span></span>
  <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>bar<span class="token punctuation">'</span></span>
  <span class="token attr-name">baz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>baz<span class="token punctuation">'</span></span>
<span class="token punctuation">/&gt;</span></span>
</code></pre></div><h2 id="方法"><a href="#方法" class="header-anchor">#</a> 方法</h2> <ul><li>使用箭头函数包裹本地变量</li></ul> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token keyword">function</span> <span class="token function">ItemList</span> <span class="token punctuation">(</span><span class="token parameter">props</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ul</span><span class="token punctuation">&gt;</span></span><span class="token plain-text">
      </span><span class="token punctuation">{</span>props<span class="token punctuation">.</span>items<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">item<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">(</span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Item</span></span>
          <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>item<span class="token punctuation">.</span>key<span class="token punctuation">}</span></span>
          <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token function">doSomethingWith</span><span class="token punctuation">(</span>item<span class="token punctuation">.</span>name<span class="token punctuation">,</span> index<span class="token punctuation">)</span><span class="token punctuation">}</span></span>
        <span class="token punctuation">/&gt;</span></span>
      <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token plain-text">
    </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span class="token punctuation">&gt;</span></span>
  <span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre></div><ul><li>类组件的内部方法不要使用下划线前缀</li></ul> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token keyword">class</span> <span class="token class-name">extends</span> React<span class="token punctuation">.</span>Component <span class="token punctuation">{</span>
  <span class="token function">_onClickSubmit</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// do stuff</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// other stuff</span>
<span class="token punctuation">}</span>

<span class="token comment">// good</span>
<span class="token keyword">class</span> <span class="token class-name">extends</span> React<span class="token punctuation">.</span>Component <span class="token punctuation">{</span>
  <span class="token function">onClickSubmit</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// do stuff</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// other stuff</span>
<span class="token punctuation">}</span>
</code></pre></div><ul><li>确保在 render 方法中存在返回值，eslint: require-render-return</li></ul> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token function">render</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token punctuation">/&gt;</span></span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// good</span>
<span class="token function">render</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token punctuation">/&gt;</span></span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="hooks-书写规范"><a href="#hooks-书写规范" class="header-anchor">#</a> Hooks 书写规范</h2> <ul><li><p>Hooks 只能应用于函数式组件中</p></li> <li><p>只在 React 函数最顶层使用 Hooks</p></li></ul> <blockquote><p>不要在循环，条件或嵌套函数中调用 Hook， 确保总是在你的 React 函数的最顶层调用他们</p></blockquote> <div class="language-jsx extra-class"><pre class="language-jsx"><code><span class="token comment">// bad</span>
<span class="token keyword">function</span> <span class="token function">a</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> <span class="token punctuation">[</span>count<span class="token punctuation">,</span> setCount<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useState</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
  <span class="token function">useEffect</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token function">persistForm</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    localStorage<span class="token punctuation">.</span><span class="token function">setItem</span><span class="token punctuation">(</span><span class="token string">'formData'</span><span class="token punctuation">,</span> accountName<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> <span class="token function-variable function">x</span> <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
  <span class="token keyword">const</span> <span class="token punctuation">[</span>timer<span class="token punctuation">,</span> setTimer<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useState</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>

  <span class="token comment">// main logic</span>
<span class="token punctuation">}</span>

<span class="token comment">// bad</span>
<span class="token keyword">function</span> <span class="token function">a</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> <span class="token punctuation">[</span>count<span class="token punctuation">,</span> setCount<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useState</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
  <span class="token function">useEffect</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token function">persistForm</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    localStorage<span class="token punctuation">.</span><span class="token function">setItem</span><span class="token punctuation">(</span><span class="token string">'formData'</span><span class="token punctuation">,</span> accountName<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> <span class="token punctuation">[</span>timer<span class="token punctuation">,</span> setTimer<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useState</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> <span class="token function-variable function">x</span> <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
  <span class="token comment">// main logic</span>
<span class="token punctuation">}</span>
</code></pre></div></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">10/9/2023, 2:58:10 PM</span></div></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-cb1513f6><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#基本规则" class="sidebar-link reco-side-基本规则" data-v-cb1513f6>基本规则</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#命名规范" class="sidebar-link reco-side-命名规范" data-v-cb1513f6>命名规范</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#class-component-vs-functional-component" class="sidebar-link reco-side-class-component-vs-functional-component" data-v-cb1513f6>Class Component VS Functional Component</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#对齐" class="sidebar-link reco-side-对齐" data-v-cb1513f6>对齐</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#空格" class="sidebar-link reco-side-空格" data-v-cb1513f6>空格</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#引号" class="sidebar-link reco-side-引号" data-v-cb1513f6>引号</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#属性" class="sidebar-link reco-side-属性" data-v-cb1513f6>属性</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#refs" class="sidebar-link reco-side-refs" data-v-cb1513f6>Refs</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#圆括号" class="sidebar-link reco-side-圆括号" data-v-cb1513f6>圆括号</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#标签" class="sidebar-link reco-side-标签" data-v-cb1513f6>标签</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#方法" class="sidebar-link reco-side-方法" data-v-cb1513f6>方法</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/react-standards.html#hooks-书写规范" class="sidebar-link reco-side-hooks-书写规范" data-v-cb1513f6>Hooks 书写规范</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/sjj-blog/assets/js/app.ab5bad9b.js" defer></script><script src="/sjj-blog/assets/js/3.136f62ef.js" defer></script><script src="/sjj-blog/assets/js/1.a27fba8e.js" defer></script><script src="/sjj-blog/assets/js/19.7e0f4bf8.js" defer></script>
  </body>
</html>
